package com.tianqicode.demo.service.impl;

import com.tianqicode.demo.dao.ServiceDao;
import com.tianqicode.demo.listener.CustomEvent;
import com.tianqicode.demo.service.ComponentService;
import com.tianqicode.demo.service.IService;
import com.tianqicode.spring.beans.BeansException;
import com.tianqicode.spring.context.ApplicationContext;
import com.tianqicode.spring.context.ApplicationContextAware;
import com.tianqicode.spring.context.ApplicationEventPublisher;
import com.tianqicode.spring.context.ApplicationEventPublisherAware;

public class ServiceImpl implements IService, ApplicationContextAware, ApplicationEventPublisherAware {

    private ServiceDao serviceDao;
    private ComponentService componentService;

    private ApplicationEventPublisher applicationEventPublisher;

    public ServiceImpl(ServiceDao serviceDao) {
        this.serviceDao = serviceDao;
    }

    public ServiceImpl() {
    }

    @Override
    public String doService() {
        System.out.println(serviceDao.getData());
        System.out.println("做了一些业务");
        applicationEventPublisher.publishEvent(new CustomEvent(this, 1019129009086763L, "业务完成了"));
        return "做了一些业务";
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println(this.getClass().getSimpleName()+":"+applicationContext);
    }

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }
}
